package com.ruoyi.hr.controller.hr.salary.specialPersonRegister;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.framework.util.ShiroUtils;
import com.ruoyi.hr.domain.Authority;
import com.ruoyi.hr.service.AuthorityService;
import com.ruoyi.hr.service.CompanysService;
import com.ruoyi.hr.service.DepartmentsService;
import com.ruoyi.hr.service.salary.SpecialPersonRegisterService;
import com.ruoyi.system.domain.SysUser;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * @author zeo
 * @explain 特殊人员登记
 * @date 2020/2/11
 */
@Controller
@RequestMapping("/specialPersonRegister")
public class SpecialPersonRegisterController extends BaseController {

    @Autowired
    private SpecialPersonRegisterService specialPersonRegisterService;

    @Autowired
    private AuthorityService authorityService;

    @Autowired
    private CompanysService companysService;

    @Autowired
    private DepartmentsService departmentsService;

    private String prefix = "hr/salary/specialPersonRegister";

    @GetMapping()
    public String specialPersonRegister() {
        return prefix + "/specialPersonRegister";
    }

    /**
     * 获取特殊人员登记数据
     *
     * @return
     */
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(@RequestParam Map<String, Object> map) {
        SysUser user = ShiroUtils.getSysUser();
        List<Authority> authorityList = authorityService.getAuthorityUser(user.getUserId().toString());
        int isAdmin = 0;
        if (authorityList.size() == 1) {
            if (authorityList.get(0).getIsAdmin() != null) {
                isAdmin = 1;
            }
        }
        startPage();
        List<Map<String, Object>> list = specialPersonRegisterService.findData(authorityList, map, isAdmin);
        return getDataTable(list);
    }

    /**
     * 跳转新增页面
     */
    @GetMapping("/add")
    public String add(ModelMap mmap) {
        //公司
        mmap.put("companys", companysService.findAllCompanys(null));
        //部门
        mmap.put("departments", departmentsService.findAllDepart());
        return prefix + "/add";
    }

    /**
     * 跳转修改页面
     *
     * @param id
     * @param mmap
     * @return
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") int id, ModelMap mmap) {
        Map<String, Object> map = specialPersonRegisterService.findDataById(id);
        mmap.put("map", map);
        //公司
        mmap.put("companys", companysService.findAllCompanys(null));
        //部门
        mmap.put("departments", departmentsService.findAllDepart());
        return prefix + "/edit";
    }

    @PostMapping("/remove")
    @ResponseBody
    public AjaxResult remove(@Validated String ids) {
        return toAjax(specialPersonRegisterService.delete(ids));
    }

    /**
     * 修改操作
     *
     * @return
     */
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult edit(@RequestParam Map map) {
        return toAjax(specialPersonRegisterService.edit(map));
    }

    /**
     * 新增操作
     *
     * @return
     */
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult add(@RequestParam Map map) {
        return toAjax(specialPersonRegisterService.add(map));
    }

    /**
     * 获取银行类别
     */
    @PostMapping("/getyhlb")
    @ResponseBody
    public String getyhlb(String bcid) {
        return specialPersonRegisterService.getyhlb(bcid);
    }

    /**
     * 获取pgid
     */
    @PostMapping("/getpgid")
    @ResponseBody
    public String getpgid(@RequestParam Map map) {
        return specialPersonRegisterService.getpgid(map);
    }
}
